//
//  ScrollableLabel.swift
//  SCA
//
//  Created by tjun on 2025/9/12.
//

import UIKit
import SnapKit

class ScrollableLabel: UIView {
    
    private let scrollView = UIScrollView()
    private let label = UILabel()
    
    var text: String? {
        didSet {
            label.text = text
            layoutIfNeeded()
        }
    }
    
    var attributedText: NSAttributedString? {
        didSet {
            label.attributedText = attributedText
            layoutIfNeeded()
        }
    }
    
    var textColor: UIColor = .black {
        didSet { label.textColor = textColor }
    }
    
    var font: UIFont = .systemFont(ofSize: 16) {
        didSet { label.font = font }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupViews()
    }
    
    private func setupViews() {
        clipsToBounds = true
        
        scrollView.showsVerticalScrollIndicator = false
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.isScrollEnabled = true
        addSubview(scrollView)
        
        label.numberOfLines = 0
        scrollView.addSubview(label)
        
        scrollView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        label.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.width.equalTo(scrollView.snp.width)
            make.bottom.equalToSuperview() // 让内容撑开
        }
    }
}
